1675C - Detective Task - CodeForces Solution


implementation *1100

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    s = input()
    count = 0
    for x in s:
        if x == '?':
            count+=1
        elif x == '0':
            count+=1
            break
        elif x == '1':
            count = 1
    print(count)

C++ Code:

#include <bits/stdc++.h>
#define lli           long long int
#define pb            push_back
#define fi            first
#define se            second
#define vi            vector<lli>
#define pi      	  pair<int,int>
#define all(a)        a.begin(),a.end()
#define mem(h,x)      memset(h,x,sizeof(h))
#define intmx         1000000007
using namespace std;

void solve()
{
	//CROSS CHECK CORNER CASES(N==1)
	string a;
	cin >> a;
	int ans = 0, n = a.size(), l = 0, r = n - 1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == '1')
			l = i;
	}
	for (int i = n - 1; i >= 0; i--)
	{
		if (a[i] == '0')
			r = i;
	}
	cout << r - l + 1 << '\n';
}
int main()
{
//	auto start=chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(false);
	int t = 1;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> t;
	while (t--)
		solve();
//	auto stop=chrono::high_resolution_clock::now();
//	auto durn=chrono::duration_cast<chrono::microseconds>(stop-start);
//	cerr<<"\n"<<durn.count()/1000.0<<" ms\n";
}


Comments

Submit
0 Comments
More Questions

630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation
550C - Divisibility by Eight
5A - Chat Servers Outgoing Traffic
615A - Bulbs
5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman
320B - Ping-Pong (Easy Version)
948A - Protect Sheep
387A - George and Sleep
53A - Autocomplete
1729G - Cut Substrings
805B - 3-palindrome
805C - Find Amir